class SaleInquiryProduct {
  String? id;
  String? productCode; //产品编码
  String? productId; //产品id
  String? productName; //产品名称
  String? description; //规格型号
  String? technicalRequirement; //技术要求
  String? comment; //备注
  String? unit; //单位
  num? quantity; //数量
  num? unitPrice; //单价
  String? sum; //小计
  String? inquiryNo; //询价单编号
  String? partnerId; //询价单位id
  String? partnerName; //询价单位
  String? userId; //事业部
  String? userName; //事业部
  String? inquiryId; //inquiry_id sale_inquiry_form
  num? taxrate; //退税率
  num? foreignprice; //销售单价（外币）
  num? taxinclusiveprice; //核算含税价格（元）
  num? notaxinclusiveprice; //核算不含税价格（元）
  num? taxsurcharges; //单位补税及税金附加（元）
  num? singleprofitmargin; //单项利润率
  num? summarycost; //单项换汇成本
  String? edit; //价格是否调整

  SaleInquiryProduct({
    this.id,
    this.productCode,
    this.productId,
    this.productName,
    this.description,
    this.technicalRequirement,
    this.comment,
    this.unit,
    this.quantity,
    this.unitPrice,
    this.sum,
    this.inquiryNo,
    this.partnerId,
    this.partnerName,
    this.userId,
    this.userName,
    this.inquiryId,
    this.taxrate,
    this.foreignprice,
    this.taxinclusiveprice,
    this.notaxinclusiveprice,
    this.taxsurcharges,
    this.singleprofitmargin,
    this.summarycost,
    this.edit,
  });

  SaleInquiryProduct copyWith({
    String? id,
    String? productCode,
    String? productName,
    String? description,
    String? comment,
    String? unit,
    num? quantity,
    num? unitPrice,
    String? sum,
    String? inquiryNo,
    String? partnerId,
    String? userId,
  }) {
    return new SaleInquiryProduct(
      id: id ?? this.id,
      productCode: productCode ?? this.productCode,
      productName: productName ?? this.productName,
      description: description ?? this.description,
      comment: comment ?? this.comment,
      unit: unit ?? this.unit,
      quantity: quantity ?? this.quantity,
      unitPrice: unitPrice ?? this.unitPrice,
      sum: sum ?? this.sum,
      inquiryNo: inquiryNo ?? this.inquiryNo,
      partnerId: partnerId ?? this.partnerId,
      userId: userId ?? this.userId,
    );
  }

  @override
  String toString() {
    return '''SaleInquiryProduct{
      id: $id,
      productCode: $productCode,
      productName: $productName,
      description: $description,
      comment: $comment,
      unit: $unit,
      quantity: $quantity,
      unitPrice: $unitPrice,
      sum: $sum,
      inquiryNo: $inquiryNo,
      partnerId: $partnerId,
      userId: $userId,
      taxrate: $taxrate,
      taxinclusiveprice: $taxinclusiveprice,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is SaleInquiryProduct &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          productCode == other.productCode &&
          productName == other.productName &&
          description == other.description &&
          comment == other.comment &&
          unit == other.unit &&
          quantity == other.quantity &&
          unitPrice == other.unitPrice &&
          sum == other.sum &&
          inquiryNo == other.inquiryNo &&
          partnerId == other.partnerId &&
          userId == other.userId);

  factory SaleInquiryProduct.fromMap(Map<String, dynamic> map) {
    return new SaleInquiryProduct(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      productCode: map['product_id']['default_code'] != false
          ? map['product_id']['default_code'].toString() as String?
          : "",
      productId: map['product_id'] != false
          ? map['product_id']['id'].toString() as String?
          : "",
      productName: map['product_id']['name'] != false
          ? map['product_id']['name'].toString() as String?
          : "",
      description: map['product_id']['description'] != false
          ? map['product_id']['description'].toString() as String?
          : "",
      technicalRequirement: map['technical_requirement'] != false
          ? map['technical_requirement'].toString() as String?
          : "",
      comment:
          map['comment'] != false ? map['comment'].toString() as String? : "",
      unit: map['product_id'] != false
          ? map['product_id']['unit'].toString() as String?
          : "",
      quantity: map['quantity'] != false ? map['quantity'] : null,
      unitPrice: map['unit_price'] != false ? map['unit_price'] : null,
      sum: (map['quantity'] * map['unit_price']).toString(),
      taxrate: map['taxrate'] != false ? map['taxrate'] : null,
      foreignprice: map['foreignprice'] != false ? map['foreignprice'] : null,
      taxinclusiveprice:
          map['taxinclusiveprice'] != false ? map['taxinclusiveprice'] : null,
      notaxinclusiveprice: map['notaxinclusiveprice'] != false
          ? map['notaxinclusiveprice']
          : null,
      taxsurcharges:
          map['taxsurcharges'] != false ? map['taxsurcharges'] : null,
      singleprofitmargin:
          map['singleprofitmargin'] != false ? map['singleprofitmargin'] : null,
      summarycost: map['summarycost'] != false ? map['summarycost'] : null,
      edit: map['edit'] != false ? map['edit'] : '',
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'productCode': this.productCode,
      'productName': this.productName,
      'description': this.description,
      'comment': this.comment,
      'unit': this.unit,
      'quantity': this.quantity,
      'unitPrice': this.unitPrice,
      'sum': this.sum,
      'inquiryNo': this.inquiryNo,
      'partnerId': this.partnerId,
      'userId': this.userId,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.inquiryId != null && this.inquiryId != '')
        ['inquiry_id', '=', int.parse(this.inquiryId!)],
    ] as List;
    // if (list.length == 0) {
    //   list.add(['id', '!=', null]);
    // }
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'product_id': this.productId,
      'inquiry_id': this.inquiryId,
      'comment': this.comment,
      'technical_requirement': this.technicalRequirement,
      'quantity': this.quantity,
      'unit_price': this.unitPrice,
      'taxrate': this.taxrate,
      'foreignprice': this.foreignprice,
      'taxinclusiveprice': this.taxinclusiveprice,
      'notaxinclusiveprice': this.notaxinclusiveprice,
      'taxsurcharges': this.taxsurcharges,
      'singleprofitmargin': this.singleprofitmargin,
      'summarycost': this.summarycost,
    } as Map<String, dynamic>;
  }

  Map<String, dynamic> toOdooPrice() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'unit_price': this.unitPrice,
      'edit': this.edit,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
